//
//  CompanyTaskPercentView.m
//  MarkPlatform
//
//  Created by xiao6 on 2017/12/27.
//  Copyright © 2017年 AT. All rights reserved.
//

#import "CompanyTaskPercentView.h"

@interface CompanyTaskPercentView()
@property (nonatomic, strong) UIView *backLineView;
@property (nonatomic, strong) UIView *colorLineView;
@end

@implementation CompanyTaskPercentView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.backLineView];
        [self addSubview:self.colorLineView];
    }
    return self;
}
- (void)setPercent:(CGFloat)percent {
    if (percent < 0 || percent > 1) {
        return;
    }
    _percent = percent;
    [self setNeedsLayout];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.backLineView.frame = CGRectMake(0, (self.height - 2)/2.f, self.width, 5);
    CGFloat colorLineLength = self.backLineView.width * self.percent;
    self.colorLineView.frame = CGRectMake(0, self.backLineView.top, colorLineLength, self.backLineView.height);
    [self.backLineView.layer removeAllSublayers];
    [self.colorLineView.layer removeAllSublayers];
    [self drawLineOfDashByCAShapeLayer:self.backLineView lineLength:5 lineSpacing:3 lineColor:[UIColor colorWithRGB:0xECEFF1] lineWidth:2.f];
    [self drawLineOfDashByCAShapeLayer:self.colorLineView lineLength:5 lineSpacing:3 lineColor:[UIColor colorWithRGB:0xFC435B] lineWidth:2.f];
    
}
- (UIView *)backLineView {
    if (!_backLineView) {
        _backLineView = [[UIView alloc] init];
    }
    return _backLineView;
}
- (UIView *)colorLineView {
    if (!_colorLineView) {
        _colorLineView = [[UIView alloc] init];
    }
    return _colorLineView;
}

@end
